from django.db import models
from django.contrib import admin
import datetime


class Poll(models.Model):
    question = models.CharField(max_length=200)
    answer = models.CharField(max_length=200, blank=True)
    pub_date = models.DateTimeField('date published')

    def __unicode__(self):
        return u'%s' % self.question

    def was_published_today(self):
        return self.pub_date.date() == datetime.date.today()
    was_published_today.short_description = 'Published today?'

class Choice(models.Model):
    poll = models.ForeignKey(Poll)
    choice = models.CharField(max_length=200)
    votes = models.IntegerField()


#class ChoiceInline(admin.StackedInline):
class ChoiceInline(admin.TabularInline):
    model = Choice
    extra = 3

class PollAdmin(admin.ModelAdmin):
    # fields = ['pub_date', 'question']
    list_display = ('question', 'answer', 'pub_date', 'was_published_today')
    fieldsets = [
            (None, {'fields': ['question']}),
            ('Date infomation', {'fields': ['pub_date', 'answer'], 'classes': ['collapse']}),
            ]
    inlines = [ChoiceInline]
    list_filter = ['pub_date']
    search_fields = ['question']
    date_hierarchy = 'pub_date'


admin.site.register(Poll, PollAdmin)



# admin.site.register(Choice)
